#ifndef		___DATA_HOST_IMP___
#define		___DATA_HOST_IMP___

#include "Service/ServiceImp.h"
#include "ServiceDataSMS.h"
#include "Service/Session.h"
#include "Message/MsgBuilderIf.h"

//
//	Network Service 
//
//
class ServiceImpHost : public ServiceImp
{
public:
	enum
	{
		num_working_thread	=	4,
		num_session_mgrs	=	2,
	};


	ServiceImpHost();
	virtual ~ServiceImpHost();

	virtual void init(ServiceData& data);

	//
	//	session recycle & reuse
	//
	virtual bool	createSession(Session*& pSes);
	virtual	bool	releaseSession(Session*  pSes);

	//
	//	get session by session/entity id
	//
	Session*	getSession(int sid);
	void		rmvSession(int sid);

	//
	//	session start & end
	//
	virtual void onSessionStart(Session* pSes, const boost::system::error_code& error);
	virtual void onSessionEnd(Session* pSes);
protected:
	virtual void onStart();
	virtual void onStop();

	//
	//	callbacks
	//
	virtual void onTimer();
	virtual void onDispatchMsg(IMsg* pMsg);
	//
	//	handle control message
	//
	virtual void onControlMsg(IMsg* pMsg);

	void post_accept();
protected:

	boost::asio::io_service::work	m_theEmptyWork;
	boost::asio::ip::tcp::endpoint	m_theEndPoint;
	boost::asio::ip::tcp::acceptor	m_theAcceptor;

	typedef stdext::hash_map<int, Session*>	SessionMap;
	SessionMap		m_mapSID2Session;
	int				m_nCurrentSessionID;

	Service*	m_wpSvcLgc;

	MsgBufferFactory	m_theMsgBuffFact;

	IMsgBuilder*		m_pMsgBuilder;

	//
	//	configurations from properties file
	//
	short		m_nPort;
};

#endif
